package actions;

import java.awt.event.ActionEvent;

import javax.swing.JButton;

import parameters.RLM_Parameters;

import client.ClientApplication;
import client_gui.ClientWindow;

public class ExitAction extends RLMAbstractAction {

	
	public ExitAction(ClientWindow owner) {
		setActionOwner(owner);
//		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0));
		putValue(SMALL_ICON, loadIcon("images/exit.png"));
		putValue(NAME, "Exit");
		putValue(SHORT_DESCRIPTION, "Exit");
		
		setActionItem();
	}
	
	public void actionPerformed(ActionEvent e) {
		getActionOwner().getApplicaton().stopClientServer();
		
		if ( getActionOwner().getActionManager().getLogoutAction().isEnabled() == true ) {
			JButton logoutButton = new JButton(getActionOwner().getActionManager().getLogoutAction());
			logoutButton.doClick();			
		}
		else {
			getActionOwner().getApplicaton().writeInputParameters();
			RLM_Parameters.storeParameters();
			ClientApplication.multicastReceived = false;
		}

		getActionOwner().dispose();
		System.exit(0);
	}
	
}
